//
//  ZBXMContentView.swift
//  zhiboxiangmu
//
//  Created by 丁鼎 on 2017/7/4.
//  Copyright © 2017年 丁鼎. All rights reserved.
//

import UIKit

class ZBXMPageView: UIView {

    //mark:属性
    var titles :[String]
    var  style :ZBXMPageStyle
    var childVcs :[UIViewController]
    var parentVc :UIViewController
    
    //mark:构造函数
    //在构造函数init之前,把所有属性都初始化好
    init(frame:CGRect,title:[String],style:ZBXMPageStyle,childVcs :[UIViewController],parentVc:UIViewController)
    {
        
        self.titles = title
        self.style = style
        self.childVcs = childVcs
        self.parentVc = parentVc
        super.init(frame: frame)
        setupUI()
    }
    
    //所有带required都是需要重新构造的
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    

}




extension ZBXMPageView{
    
    fileprivate func setupUI(){
        
        //1,创建titleView
        let titleFrame = CGRect(x: 0, y: 64, width:bounds.width, height: style.titleHeight)
        let titleview = ZBXMTitleView(frame: titleFrame, titles: titles, style: style)
        titleview.backgroundColor = UIColor.blue
        addSubview(titleview)
        
        //2,创建pageview
        let pageFrame = CGRect(x: 0, y: titleFrame.maxY, width: bounds.width, height: bounds.height - titleFrame.height - 64)
        let pageView = ZBXMContentView(frame: pageFrame, childVcs: childVcs, parentVc: parentVc)
        pageView.backgroundColor = UIColor(hexString: "D7D7D7")
        addSubview(pageView)
        
        //3,让titleview和pageview联动
        titleview.delegate = pageView
        pageView.delegate  = titleview
    }
    
}
